package cn.tedu.charging.device.controller;

import cn.tedu.charging.commen.JsonResult;
import cn.tedu.charging.commen.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.commen.pojo.vo.ChargingStationVO;
import cn.tedu.charging.commen.pojo.vo.StationVO;
import cn.tedu.charging.device.pojo.po.ChargingStationPO;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备接口")
@Slf4j
@RestController
@RequestMapping("/device")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @ApiOperation("获取场站信息")
    @GetMapping("station/info/{gunId}")
    public JsonResult<StationVO> getStationInfo(@PathVariable("gunId") Integer gunId){
        log.debug("获取场站信息，参数={}",gunId);
        StationVO stationVO = deviceService.getStationInfo(gunId);
        log.debug("获取场站信息，入参:{},结果:{}",gunId,stationVO);
        JsonResult<StationVO> result = JsonResult.ok(stationVO, "获取场站信息成功");
        log.debug("获取场站信息，入参:{},返回:{}",gunId,result);
        return result;
    }

    @ApiOperation("更新枪状态")
    @PostMapping("station/gun/status/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.debug("更新枪状态，参数={}",gunStatusUpdateParam);
        Boolean success = deviceService.updateGunStatus(gunStatusUpdateParam);
        log.debug("更新枪状态，入参:{},结果:{}",gunStatusUpdateParam,success);

        JsonResult<Boolean> result = JsonResult.ok(success, "更新枪状态成功");
        log.debug("更新枪状态，入参:{},返回:{}",gunStatusUpdateParam,result);
        return result;
    }

    @ApiOperation("获取附近场站")
    @GetMapping("/station/near")
    public JsonResult<List<ChargingStationVO>> getNearStations(Double longitude, Double latitude, Double distance){
        log.debug("获取附近场站，参数:经度:{},纬度:{},半径:{}",longitude,latitude,distance);
        List<ChargingStationVO> stationVOS = deviceService.getNearStations(longitude, latitude, distance);
        log.debug("获取附近场站，入参:{},{},{},结果:{}",longitude,latitude,distance,stationVOS);
        return JsonResult.ok(stationVOS,"获取附近场站成功");
    }
}
